export interface TeamPokemon {
  id: number
  name: string
  sprite: string
  types: string[]
  level: number
  moves: {
    name: string
    type?: string
    power?: number
    accuracy?: number
  }[]
}

export const teamStorage = {
  getTeam(): TeamPokemon[] {
    const team = localStorage.getItem('pokemon-team')
    return team ? JSON.parse(team) : []
  },

  setTeam(team: TeamPokemon[]) {
    localStorage.setItem('pokemon-team', JSON.stringify(team))
  },

  addPokemon(pokemon: TeamPokemon) {
    const team = this.getTeam()
    if (team.length >= 6) {
      throw new Error('Team is full')
    }
    if (team.some(p => p.id === pokemon.id)) {
      throw new Error('Pokemon already in team')
    }
    team.push(pokemon)
    this.setTeam(team)
  },

  removePokemon(id: number) {
    const team = this.getTeam()
    const index = team.findIndex(p => p.id === id)
    if (index !== -1) {
      team.splice(index, 1)
      this.setTeam(team)
    }
  }
}
